import { CellRenderer } from "../../../../fl/controls/listClasses/CellRenderer";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { ResouceConst } from "../../../component/gconst/ResouceConst";
import { ObjCreate } from "../common/ObjCreate";
import { Language } from "../../../../extend/language/Language";
import { SMiniGroupInfo } from "../../../../Message/BroadCast/SMiniGroupInfo";
import { SEntityInfo } from "../../../../Message/BroadCast/SEntityInfo";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { AvatarInfo } from "../../resource/info/AvatarInfo";
import { AvatarType } from "../../resource/info/AvatarType";
import { PlayerMiniInfo } from "../../model/PlayerMiniInfo";
import { SPublicMiniPlayer } from "../../../../Message/Public/SPublicMiniPlayer";
import { PlayerOpRegister } from "../common/menu/PlayerOpRegister";
import { PlayerOpMenuConst } from "../common/menu/PlayerOpMenuConst";
import { ImageInfo } from "../../../../com/gengine/resource/info/ImageInfo";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { GLabel } from "../../../../com/mui/controls/GLabel";
import { GButton } from "../../../../com/mui/controls/GButton";
//class NearbyGroupCellRenderer
    
    export  class NearbyGroupCellRenderer extends CellRenderer
    {
        constructor()
        {
            super();
            this.mouseChildren = true;
            this.initStyle();
            this.createChildren();
            return;
        }

        /* internal  */initStyle(): void
        {
            var loc1=GlobalClass.getScaleBitmap("Friend_over", new Object /* flash.geom.Rectangle */(85, 5, 4, 10));
            loc1.width = 260;
            loc1.height = 38;
            this.setStyle("upSkin", new Object /* flash.display.Bitmap */());
            this.setStyle("downSkin", loc1);
            this.setStyle("overSkin", loc1);
            this.setStyle("selectedDownSkin", loc1);
            this.setStyle("selectedOverSkin", loc1);
            this.setStyle("selectedUpSkin", loc1);
            return;
        }

        /* internal  */createChildren(): void
        {
            var loc1=ResouceConst.getScaleBitmap("SplitLine");
            loc1.width = 260;
            this.addChild(loc1);
            this._headImg = new Object /* flash.display.Bitmap */();
            this._headImg.width = 20;
            this._headImg.height = 20;
            this._headImg.x = 5;
            this._headImg.y = 7;
            this.addChild(this._headImg);
            this._nameLabel = ObjCreate.createLabel("", 30, 9, 120, 20, flash.text.TextFormatAlign.LEFT, this, false, 11661311);
            this._levelLabel = ObjCreate.createLabel("", 110, 9, 50, 20, flash.text.TextFormatAlign.LEFT, this, false, 11661311);
            this._numLabel = ObjCreate.createLabel("", 160, 9, 50, 20, flash.text.TextFormatAlign.LEFT, this, false, 11661311);
            this._operMenuSprite = new Object /* flash.display.Sprite */();
            this._operMenuSprite.buttonMode = true;
            this._operMenuSprite.graphics.beginFill(16711680, 0);
            this._operMenuSprite.graphics.drawRect(0, 0, 200, 38);
            this._operMenuSprite.cacheAsBitmap = true;
            this.addChild(this._operMenuSprite);
            this._joinBtn = ObjCreate.createGButton(Language.getString(62046), 205, 8, 49, 22, this, "ButtonMini");
            this._joinBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onButtonClick);
            this._joinBtn.drawNow();
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            var loc1=null;
            var loc2=null;
            super.data = arg1;
            if (arg1) 
            {
                this._isCross = arg1["isCross"];
                loc1 = arg1["group"] as SMiniGroupInfo;
                loc2 = arg1["player"] as SEntityInfo;
                if (loc1 && loc2) 
                {
                    this._nameLabel.htmlText = HTMLUtil.addColor(loc1.captionName, "#B1EFFE");
                    this._levelLabel.htmlText = HTMLUtil.addColor(String(loc1.captionLevel), "#B1EFFE");
                    this._numLabel.htmlText = HTMLUtil.addColor(loc1.playerCount + "/" + loc1.maxPlayerCount, "#B1EFFE");
                    AvatarInfo.getAvatar(loc1.captainCamp, loc1.captainSex, AvatarType.SMALL, this.onAvatarLoaded, loc2.avatarId);
                    if (!this._playerMiniInfo) 
                    {
                        this._playerMiniInfo = new PlayerMiniInfo(new SPublicMiniPlayer());
                    }
                    this._playerMiniInfo.camp = loc1.captainCamp;
                    this._playerMiniInfo.sex = loc1.captainSex;
                    this._playerMiniInfo.entityId = loc1.captionId;
                    this._playerMiniInfo.playerName = loc1.captionName;
                    this._playerMiniInfo.level = loc1.captionLevel;
                    this._playerMiniInfo.online = true;
                    PlayerOpRegister.Register(this._operMenuSprite, this._playerMiniInfo, PlayerOpMenuConst.NearbyTeamOpMenu);
                }
            }
            return;
        }

        /* internal  */onAvatarLoaded(arg1: ImageInfo): void
        {
            this._headImg.bitmapData = arg1.bitmapData;
            this._headImg.width = 22;
            this._headImg.height = 22;
            return;
        }

        /* internal  */onButtonClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=null;
            if (data) 
            {
                loc1 = data["player"] as SEntityInfo;
                if (this._isCross) 
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.CrossGroup_DoApply, loc1.entityId, false, true, false));
                }
                else 
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.Group_DoApply, loc1.entityId, false, true, false));
                }
            }
            return;
        }

        public /* override */ set label(arg1: string)
        {
            return;
        }

        /* internal */ /* var */_isCross: Boolean;

        /* internal */ /* var */_playerMiniInfo: PlayerMiniInfo;

        /* internal */ /* var */_operMenuSprite: Object /* flash.display.Sprite */;

        /* internal */ /* var */_headImg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_nameLabel: GLabel;

        /* internal */ /* var */_levelLabel: GLabel;

        /* internal */ /* var */_numLabel: GLabel;

        /* internal */ /* var */_joinBtn: GButton;
    }
